<template>
<div class="page">
	<div v-if="resultNew.length>0">
		<table class="layui-hide" id="tablelist" lay-filter="tablelist"></table>
		<div id="laypage"></div>
	</div>
	<div v-else style="padding:50px 0;text-align: center;border:1px solid #eee;margin-top:20px;">暂无数据</div>
</div>
</template>
<script>
	export default {
	  name:'tables',
	  props: {
	  	    height:'',
			fdate:'',
			result:'',
			totalCount:'',
			pageNumber:'',
			fbtn:'',//按钮

      },
	  data () {
	    return {
	        pageNumberNew:this.pageNumber,
	        resultNew:[]
	    }
	  },
	  mounted(){
	  	this.gettable()
	  },
	  methods: {
	  	gettable:function(){
  		var _this=this;
  		var h=this.height?this.height:'312';
  	    table = layui.table;
  	    if(_this.totalCount==1.1){
  	    	var ispage=true;
  	    }
  	    else{
  	    	var ispage=false;
  	    }
		  	setTimeout(function(){
			  	table.render({
				    elem: '#tablelist'
				    //,height:h //表格的高度
				    ,data:_this.result//url内容
				    ,cols:_this.fdate//表头
				    ,page:ispage  //开启分页
				   // ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
				});
				if(_this.totalCount!=1.1){
					laypage.render({
						layout: ['prev', 'page', 'next', 'count', 'skip'] //自定义分页布局skip跳转指定页码
			      		,curr:_this.pageNumber //设定初始在第 5 页
			      		,elem:'laypage'
			      		,groups: 5 //只显示 1 个连续页码
			      		,first: false //不显示首页
			      		,last: false //不显示尾页
			      		,limit:pageSize //自定义每页条数(可选配置)
			            ,count: _this.totalCount
						,jump: function(obj,first){
							if(!first){
								var pindex=obj.curr;
								_this.$parent.page(pindex);
							}
						}
					});
				}
				table.on('tool(tablelist)', function(obj){

					//alert(JSON.stringify(obj))
				    var data = obj.data;
				    if(obj.event === 'detail'){   //详情
				    	 _this.$parent.detailInfo(data);
				    }
				    else if(obj.event === 'edit'){    //编辑
				    	_this.$parent.editInfo(data);
				    }
				    else if(obj.event === 'del'){     //删除
				    	_this.$parent.delInfo(data);
				    }
				    else if(obj.event === 'enable'){   //启用
				    	_this.$parent.enableInfo(data);
				    }
				    else if(obj.event === 'forbidden'){ //禁用
				    	_this.$parent.forbiddenInfo(data);
				    }
				    else if(obj.event === 'upper'){    //上架
				    	_this.$parent.upperInfo(data);
				    }
				    else if(obj.event === 'code'){    //验码
				    	_this.$parent.codeInfo(data);
				    }
				    else if(obj.event === 'pay'){     //支付
				    	_this.$parent.payInfo(data);
				    }
				   	else if(obj.event === 'freego'){     //设免费购
				    	_this.$parent.freegoInfo(data);
				    }
				    else if(obj.event === 'retail'){     //分销
				    	_this.$parent.retailInfo(data);
				    }
				    else if(obj.event === 'upgrade'){  // 升级
				    	_this.$parent.upgradeInfo(data);
				    }
				     else if(obj.event === 'zhanghuzj'){  //账户增减
				    	_this.$parent.zhanghuzjInfo(data);
				    }
				   	else{
				    	return false;
				    }
				});

			},300)
	  	},

	  },
	  watch: {
	    pageNumber(newValue,oldValue){
	        this.pageNumberNew = newValue;
	        this.gettable();
	    },
	    result(newValue,oldValue){
	    	if(newValue){
	       		this.resultNew=newValue;
	        }
	    	else{
	    		this.resultNew=[];
	    	}
	        this.gettable();
	    },
	  },
	}
</script>
<style scoped>
.tablelist{height:100%;width:100%;display:block;}
</style>
